package com.triones.ljr.controller.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.triones.ljr.entity.dto.EnterpriseDO;
import com.triones.ljr.entity.vo.EnterpriseVO;
import com.triones.ljr.service.EnterpriseService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 企业管理
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/enterprise")
public class EnterpriseController extends BaseController {

    private final EnterpriseService enterpriseService;

    /**
     * 列表（分页）
     */
    @SaCheckPermission("system:enterprise:pageList")
    @GetMapping("/pageList")
    public TableDataInfo<EnterpriseVO> pageList(EnterpriseDO dto, PageQuery pageQuery) {
        return enterpriseService.pageList(dto, pageQuery);
    }

    /**
     * 审核
     */
    @SaCheckPermission("system:enterprise:audit")
    @Log(title = "企业管理", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public R<Void> audit(@RequestBody EnterpriseDO dto) {
        return toAjax(enterpriseService.audit(dto));
    }

    /**
     * 禁用/启用
     */
    @SaCheckPermission("system:enterprise:changeStatus")
    @Log(title = "企业管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public R<Void> changeStatus(@RequestBody EnterpriseDO dto) {
        return toAjax(enterpriseService.updateStatus(dto));
    }

    /**
     * 取详细信息
     * @param id
     */
    @SaCheckPermission("system:enterprise:query")
    @GetMapping(value = "/{id}")
    public R<EnterpriseVO> getInfo(@PathVariable Long id) {
        return R.ok(enterpriseService.getInfo(id));
    }
}
